package duhosdebuggolok;

import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class TerrainFeaturePainter  implements Painter{
	
	private static BufferedImage kavicsImage0 = null;
	private static BufferedImage kavicsImage1 = null;
	private static BufferedImage kavicsImage2 = null;
	private static BufferedImage bokorImage0 = null;
	private static BufferedImage bokorImage1 = null;
	private static BufferedImage bokorImage2 = null;
	private static BufferedImage tocsaImage0 = null;
	private static BufferedImage tocsaImage1 = null;
	private static BufferedImage tocsaImage2 = null;
	private TerrainFeature feature;
	
	public TerrainFeaturePainter(TerrainFeature tf) {
		feature = tf;
		if(kavicsImage0 == null || bokorImage0 == null || tocsaImage0 == null)
			loadImage();
	}
	
	private static void loadImage() {
		try {
			kavicsImage0 = ImageIO.read(new File(System.getProperty("user.dir")+"\\resources\\kavics.png"));
			bokorImage0 = ImageIO.read(new File(System.getProperty("user.dir")+"\\resources\\bokor.png"));
			tocsaImage0 = ImageIO.read(new File(System.getProperty("user.dir")+"\\resources\\tocsa.png"));
			kavicsImage1 = ImageIO.read(new File(System.getProperty("user.dir")+"\\resources\\kavics3.png"));
			bokorImage1 = ImageIO.read(new File(System.getProperty("user.dir")+"\\resources\\bokor3.png"));
			tocsaImage1 = ImageIO.read(new File(System.getProperty("user.dir")+"\\resources\\tocsa3.png"));
			kavicsImage2 = ImageIO.read(new File(System.getProperty("user.dir")+"\\resources\\kavics5.png"));
			bokorImage2 = ImageIO.read(new File(System.getProperty("user.dir")+"\\resources\\bokor5.png"));
			tocsaImage2 = ImageIO.read(new File(System.getProperty("user.dir")+"\\resources\\tocsa5.png"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public boolean paint(Graphics2D g){
		Point coord = feature.getCoord();
		int type = feature.getType();
		int radius = feature.getRadius();
		//double scale = -0.5;
		//AffineTransform affineTransform = new AffineTransform();
		Point c = GamePanel.calculate(coord);
		//affineTransform.translate((c.x-10*(radius-1)), (c.y-10*(radius-1)));
		//affineTransform.scale(2*radius+scale, 2*radius+scale);
		//affineTransform.rotate(Math.toRadians(45), 5, 5);
		switch (type) {
		case 0:
			switch (radius){
			case 0:	g.drawImage(kavicsImage0, c.x, c.y+3, null);
					break;
			case 1: g.drawImage(kavicsImage1, c.x-30, c.y-23, null);
					break;
			case 2: g.drawImage(kavicsImage2, c.x-60, c.y-50, null);
					break;
			}
			break;
		case 1:
			switch (radius) {
			case 0: g.drawImage(tocsaImage0, c.x, c.y+3, null);
					break;
			case 1: g.drawImage(tocsaImage1, c.x-30, c.y-23, null);
					break;
			case 2: g.drawImage(tocsaImage2, c.x-60, c.y-50, null);
					break;
			}
			break;
		case 2:
			switch (radius) {
			case 0: g.drawImage(bokorImage0, c.x, c.y+3, null);
					break;
			case 1: g.drawImage(bokorImage2, c.x-30, c.y-23, null);
					break;
			case 2: g.drawImage(bokorImage1, c.x-60, c.y-50, null);
					break;
			}
			break;
		}
		return true;
	}
}
